<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" href="/static/component/pear/css/pear.css" />
    <script src="/static/component/layui/layui.js"></script>
    <script src="/static/component/pear/pear.js"></script>
</head>

<body class="pear-container">
    <div class="layui-card">
        <div class="layui-card-body">
            <form class="layui-form" action="">
                <div class="layui-form-item layui-inline">
                    <div class="layui-input-inline">
                        <select name="serverid" lay-search>
                            <option value="">服务器ID</option>
                            {volist name="ServerLs" id="server"}
                            <option value="{$server.sid}">{$server.name}</option>
                            {/volist}
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="actorname" placeholder="玩家账号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" name="actoraccount" placeholder="角色名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <div class="layui-input-inline">
                        <select name="cztype" lay-search>
                            <option value="">充值类型</option>
                            <option value="alipay">支付宝</option>
                            <option value="wxpay">微信</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <div class="layui-input-inline">
                        <select name="tqktype" lay-search>
                            <option value="">特权卡类型</option>

                            <!--<option value="50">精致小卡</option>-->
                            <!--<option value="100">实惠中卡</option>-->
                            <!--<option value="300">土豪大卡</option>-->
                            <!--<option value="998">998超级卡</option>-->
                            <!--<option value="1998">1998超级卡</option>-->
                            <!--<option value="4998">4998超级卡</option>-->

                            <option value="10011">50盲盒卡</option>
                            <option value="10021">100盲盒卡</option>
                            <option value="10031">200盲盒卡</option>
                        </select>
                    </div>
                </div>

                <div class="layui-form-item layui-inline">
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
        </div>
        </form>
    </div>
    </div>
    <div class="layui-card">
        <div class="layui-card-body">
            <table id="dataTable" lay-filter="dataTable"></table>
        </div>
    </div>

    <script type="text/html" id="toolbar">
			<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="add">
		        <i class="layui-icon layui-icon-add-1"></i>
		        新增特权卡
			</button>
			<button class="pear-btn pear-btn-danger pear-btn-md" lay-event="batchRemove">
		        <i class="layui-icon layui-icon-survey"></i>
		        批量停用卡
		    </button>
            <button class="pear-btn pear-btn-danger pear-btn-md" lay-event="updatePwd">
		        <i class="layui-icon layui-icon-survey"></i>
		        修改玩家密码
		    </button>
            <button class="pear-btn pear-btn-danger pear-btn-md" lay-event="updateu2r">
		        <i class="layui-icon layui-icon-survey"></i>
		        修改玩家推广人员
		    </button>
            <button class="pear-btn pear-btn-danger pear-btn-md" lay-event="updateservername">
		        <i class="layui-icon layui-icon-survey"></i>
		        区服冠名修改
		    </button>
            
            <!-- <button class="pear-btn pear-btn-danger pear-btn-md" lay-event="getRole2Job">
		        <i class="layui-icon layui-icon-survey"></i>
		        角色转职
		    </button>
            <button class="pear-btn pear-btn-danger pear-btn-md" lay-event="getUpdateServerStatus">
		        <i class="layui-icon layui-icon-survey"></i>
		        服务器状态修改
		    </button> -->
            
		</script>


    <script type="text/html" id="tqktypeTpl">
            {{# if(d.tqktype == '50'){ }}
                <button type="button" class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs">精致小卡</button>
            {{# } else if(d.tqktype == '100'){ }}
                <button type="button" class="layui-btn layui-btn-primary layui-border-orange layui-btn-xs">实惠中卡</button>
            {{# } else if(d.tqktype == '300'){ }}
                <button type="button" class="layui-btn layui-btn-primary layui-border-red layui-btn-xs">土豪大卡</button>
            {{# } else if(d.tqktype == '998'){ }}
                <button type="button" class="layui-btn layui-btn-primary layui-border-red layui-btn-xs">998超级卡</button>
            {{# } else if(d.tqktype == '1998'){ }}
                <button type="button" class="layui-btn layui-btn-primary layui-border-red layui-btn-xs">1998超级卡</button>
            {{# } else if(d.tqktype == '4998'){ }}
                <button type="button" class="layui-btn layui-btn-primary layui-border-red layui-btn-xs">4998超级卡</button>
            {{# } else if(d.tqktype == '10011'){ }}
                <button type="button" class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs">50盲盒卡</button>
            {{# } else if(d.tqktype == '10021'){ }}
                <button type="button" class="layui-btn layui-btn-primary layui-border-orange layui-btn-xs">100盲盒卡</button>
            {{# } else if(d.tqktype == '10031'){ }}
                <button type="button" class="layui-btn layui-btn-primary layui-border-red layui-btn-xs">200盲盒卡</button>
            {{# } }}
        </script>
    <script type="text/html" id="cztypeTpl">
            {{# if(d.cztype == 'alipay'){ }}
                <span>支付宝</span>
            {{# }else if(d.cztype == 'wxpay'){ }}
                <span>微信</span>
            {{# }else{ }}
                <span>其他</span>
            {{# } }}
        </script>



    <script type="text/html" id="options">
			<!-- <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit"><i class="layui-icon layui-icon-edit"></i></button> -->
    <button class="pear-btn pear-btn-danger pear-btn-sm" lay-event="remove"><i
            class="layui-icon layui-icon-survey"></i></button>
    </script>
    <script>
        layui.use(['table', 'form', 'jquery', 'common', 'laydate'], function () {
            let table = layui.table;
            let form = layui.form;
            let $ = layui.jquery;
            let common = layui.common;
            let laydate = layui.laydate;
            let MODULE_PATH = "{$Request.root}/gm.tgczlogs_tqk/";

            let cols = [
                [{
                    type: 'checkbox'
                }, {
                    field: "id",
                    title: "ID",
                    unresize: "true",
                    align: "center",
                    hide: true
                }, {
                    field: "serverid",
                    title: "区ID",
                    unresize: "true",
                    align: "center"
                }, {
                    field: "actorid",
                    title: "角色ID",
                    unresize: "true",
                    align: "center"
                }, {
                    field: "actorname",
                    title: "角色账号",
                    unresize: "true",
                    align: "center"
                }, {
                    field: "actoraccount",
                    title: "角色名称",
                    unresize: "true",
                    align: "center"
                }, {
                    field: "ddcode",
                    title: "订单编号",
                    unresize: "true",
                    align: "center",
                    hide: true
                }, {
                    field: "cztype",
                    title: "充值类型",
                    unresize: "true",
                    align: "center",
                    templet: '#cztypeTpl'
                }, {
                    field: "status",
                    title: "状态",
                    unresize: "true",
                    align: "center",
                    hide: true
                }, {
                    field: "tqktype",
                    //    title: "特权卡类型 0. 50   1. 100   2. 300",
                    title: "特权卡类型",
                    unresize: "true",
                    align: "center",
                    templet: '#tqktypeTpl'
                }, {
                    field: "symonth",
                    title: "剩余天数",
                    unresize: "true",
                    align: "center"
                }, {
                    field: "cztime",
                    title: "发卡时间",
                    unresize: "true",
                    align: "center"
                }, {
                    field: "remake",
                    title: "备注",
                    unresize: "true",
                    align: "center"
                }, {
                    title: '操作',
                    toolbar: '#options',
                    unresize: true,
                    align: 'center',
                    width: 180
                }
                ]
            ]

            table.render({
                elem: '#dataTable',
                url: MODULE_PATH + 'index',
                page: true,
                cols: cols,
                limit: 10,
                limits: [10, 30, 50, 100, 200, 500, 1000],
                cellMinWidth: 100,
                skin: 'line',
                toolbar: '#toolbar',
                defaultToolbar: [{
                    title: '刷新',
                    layEvent: 'refresh',
                    icon: 'layui-icon-refresh',
                }, 'filter', 'print', 'exports']
            });

            table.on('tool(dataTable)', function (obj) {
                if (obj.event === 'remove') {
                    window.remove(obj);
                } else if (obj.event === 'edit') {
                    //window.edit(obj);
                }
            });

            table.on('toolbar(dataTable)', function (obj) {
                if (obj.event === 'add') {
                    window.add();
                } else if (obj.event === 'refresh') {
                    window.refresh(obj);
                } else if (obj.event === 'batchRemove') {
                    window.batchRemove(obj);
                } else if (obj.event === 'updateu2r') {
                    window.updateu2r();
                } else if (obj.event === 'updateservername') {
                    window.updateservername();
                } else if (obj.event === 'updatePwd') {
                    window.updatePwd(obj);
                } else if (obj.event === 'getRole2Job') {
                    window.getRole2Job(obj);
                } else if (obj.event === 'getUpdateServerStatus') {
                    window.getUpdateServerStatus(obj);
                }
            });

            form.on('submit(query)', function (data) {
                table.reload('dataTable', {
                    where: data.field,
                    page: { curr: 1 }
                })

                return false;
            });

            //弹出窗设置 自己设置弹出百分比
            function screen() {
                //if (typeof width !== 'number' || width === 0) {
                //width = $(window).width() * 0.5;
                // }
                //if (typeof height !== 'number' || height === 0) {
                //height = $(window).height() - 20;
                //}
                //return [width + 'px', height + 'px'];
                return ['700px', '450px'];
            }

            window.add = function () {
                layer.open({
                    type: 2,
                    maxmin: true,
                    title: '新增特权卡管理',
                    shade: 0.1,
                    area: screen(),
                    content: MODULE_PATH + 'add'
                });
            }

            window.edit = function (obj) {
                layer.open({
                    type: 2,
                    maxmin: true,
                    title: '修改特权卡管理',
                    shade: 0.1,
                    area: screen(),
                    content: MODULE_PATH + 'edit/id/' + obj.data['id']
                });
            }

            window.remove = function (obj) {
                layer.confirm('确定要停用该特权卡？', {
                    icon: 3,
                    title: '提示(多卡状态需要多次停用！)'
                }, function (index) {
                    layer.close(index);
                    let loading = layer.load();
                    $.ajax({
                        url: MODULE_PATH + 'remove',
                        data: { id: obj.data['id'] },
                        dataType: 'json',
                        type: 'POST',
                        success: function (res) {
                            layer.close(loading);
                            //判断有没有权限
                            if (res && res.code == 999) {
                                layer.msg(res.msg, {
                                    icon: 5,
                                    time: 2000,
                                })
                                return false;
                            } else if (res.code == 200) {
                                layer.msg(res.msg, {
                                    icon: 1,
                                    time: 1000
                                }, function () {
                                    obj.del();
                                });
                            } else {
                                layer.msg(res.msg, {
                                    icon: 2,
                                    time: 1000
                                });
                            }
                        }
                    })
                });
            }

            window.batchRemove = function (obj) {
                let data = table.checkStatus(obj.config.id).data;
                if (data.length === 0) {
                    layer.msg("未选中数据", {
                        icon: 3,
                        time: 1000
                    });
                    return false;
                }
                var ids = []
                var hasCheck = table.checkStatus('dataTable')
                var hasCheckData = hasCheck.data
                if (hasCheckData.length > 0) {
                    $.each(hasCheckData, function (index, element) {
                        ids.push(element.id)
                    })
                }
                layer.confirm('确定要停用这些特权卡？', {
                    icon: 3,
                    title: '提示(多卡状态需要多次停用！)'
                }, function (index) {
                    layer.close(index);
                    let loading = layer.load();
                    $.ajax({
                        url: MODULE_PATH + 'batchRemove',
                        data: { ids: ids },
                        dataType: 'json',
                        type: 'POST',
                        success: function (res) {
                            layer.close(loading);
                            //判断有没有权限
                            if (res && res.code == 999) {
                                layer.msg(res.msg, {
                                    icon: 5,
                                    time: 2000,
                                })
                                return false;
                            } else if (res.code == 200) {
                                layer.msg(res.msg, {
                                    icon: 1,
                                    time: 1000
                                }, function () {
                                    table.reload('dataTable');
                                });
                            } else {
                                layer.msg(res.msg, {
                                    icon: 2,
                                    time: 1000
                                });
                            }
                        }
                    })
                });
            }

            window.refresh = function (param) {
                table.reload('dataTable');
            }


            window.updateu2r = function (param) {
                layer.open({
                    type: 2,
                    maxmin: true,
                    title: '修改玩家推广人员',
                    shade: 0.1,
                    area: screen(),
                    content: MODULE_PATH + 'updateu2r'
                });
            }

            window.updateservername = function (param) {
                layer.open({
                    type: 2,
                    maxmin: true,
                    title: '区服冠名',
                    shade: 0.1,
                    area: screen(),
                    content: MODULE_PATH + 'updateservername'
                });
            }


            window.updatePwd = function (param) {
                layer.open({
                    type: 2,
                    maxmin: true,
                    title: '修改玩家密码',
                    shade: 0.1,
                    area: screen(),
                    content: MODULE_PATH + 'updatePwd'
                });
            }

            window.getRole2Job = function (param) {
                layer.open({
                    type: 2,
                    maxmin: true,
                    title: '角色转职',
                    shade: 0.1,
                    area: screen(),
                    content: MODULE_PATH + 'getRole2Job'
                });
            }

            window.getUpdateServerStatus = function (param) {
                layer.open({
                    type: 2,
                    maxmin: true,
                    title: '修改服务器状态',
                    shade: 0.1,
                    area: screen(),
                    content: MODULE_PATH + 'getUpdateServerStatus'
                });
            }
        })
    </script>
</body>

</html>